package com.nuhu.dao;

import com.nuhu.pojo.CustomerServiceRecord;
import com.nuhu.pojo.Worker;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface AdminWorkerDao {

    //根据id删除数据
    @Delete("delete from customer_service where Customer_Service_ID = #{CustomerServiceId}")
    public int delete(Integer CustomerServiceId);

    //新增客服
    @Insert("insert into customer_service(Customer_Service_ID, Name, Password, Contact_Number, Rating, Salary) " +
            "values (#{CustomerServiceID},#{Name},#{Password},#{ContactNumber},#{Rating},#{Salary})")
    public void insert(Worker worker);

    //更新数据
    @Update("update customer_service set  Name = #{Name}, Password = #{Password}, Contact_Number = #{ContactNumber}, Rating = #{Rating}, Salary = #{Salary} where Customer_Service_ID = #{CustomerServiceID}")
    public void update(Worker worker);

    //根据ID查询员工
    @Select("select * from customer_service where Customer_Service_ID = #{id} ")
    public Worker getByID(Integer id);

    @Select("select * from customer_service")
    List<Worker> list();

    //展现所有的员工
    @Select("SELECT * FROM customer_service LIMIT #{offset}, #{size}")
    List<Worker> getWorkers(@Param("offset") int offset, @Param("size") int size);

    //根据ID查询员工的所有信息
    @Select("select * from customer_service where Customer_Service_ID = #{WorkerID} ")
    Worker getWorkerPingFenByID(String WorkerID);

    //根据员工ID查询员工的服务记录
    @Select("select * from customer_service_record where Customer_Service_ID = #{WorkerID} ")
    List<CustomerServiceRecord> getWorkerFuWuByWorkerID(String WorkerID);


    //开除员工
    @Delete("delete from customer_service where Customer_Service_ID = #{WorkerID} ")
    Worker deleteWorker(String WorkerID);

    @Delete("delete from customer_service_record where Customer_Service_ID = #{WorkerID} ")
    void deleteWorkerRecord(String WorkerID);

    @Update("UPDATE customer_service SET Salary = Salary + #{Number} WHERE Customer_Service_ID = #{WorkerID}")
    void upSalary(@Param("Number") BigDecimal Number, @Param("WorkerID") String WorkerID);

    @Update("UPDATE customer_service SET Salary = Salary - #{Number} WHERE Customer_Service_ID = #{WorkerID}")
    void downSalary(@Param("Number") BigDecimal Number, @Param("WorkerID") String WorkerID);
}

